package com.atguigu.async;

import com.atguigu.exception.SleepUtils;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;

public class FutureDemo1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        supplyAsync();
        System.out.println("main");
        SleepUtils.sleep(3);
    }

    public static void supplyAsync() throws ExecutionException, InterruptedException {
        CompletableFuture<String> supplyAsync = CompletableFuture.supplyAsync(new Supplier<String>() {
            @Override
            public String get() {
                System.out.println(Thread.currentThread().getName() + "你好runAsync");
                SleepUtils.sleep(1);
                return "java0317";
            }
        });
        System.out.println(Thread.currentThread().getName()+":"+supplyAsync.get());
    }

    public static void runAsync(){
        CompletableFuture.runAsync(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"你好runAsync");
                SleepUtils.sleep(10);
            }
        });
    }
}
